package com.tanhua.server.controller;

import com.tanhua.server.service.BaiduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("baidu")
public class BaiduController {
    @Autowired
    private BaiduService baiduService;

    /**
     * 更新位置   传递过来的数数据时json   有latitude    longitude    addrStr
     * * @param longitude 经度
     * * @param latitude 纬度
     * * @param address 地址名称
     */
    public ResponseEntity<Void> updateLocation(@RequestParam Map<String, Object> param) {
     try {
        //获取传递过来的数据
        Double latitude = Double.valueOf(param.get("latitude").toString());
        Double longitude = Double.valueOf(param.get("longitude").toString());
        String address= param.get("address").toString();
      //调用BaiduService
        Boolean bool = this.baiduService.updateLocation(longitude, latitude, address);
        if (bool) {
         //更新成功
            return ResponseEntity.ok(null);
        }
     }catch (Exception e){
         e.printStackTrace();
     }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
